package com.huihui.activity.mine;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.huihui.R;
import com.huihui.adapter.ZujiAdapter;
import com.huihui.base.BaseActivity;
import com.huihui.bean.Goods;
import com.huihui.bean.ZuJi;
import com.huihui.bean.ZuJiInfo;
import com.huihui.widget.SwipeRecyclerView;
import org.litepal.crud.DataSupport;

import java.util.Iterator;
import java.util.List;


/**
 * 我的足迹
 */
public class MinefooterActivity extends BaseActivity {

    private List<ZuJi> mList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_minefooter);
//        getSupportActionBar().setTitle("我的足迹");
        titleView.setText("我的足迹");
        initData();
        initView();
    }

    private void initView() {
        SwipeRecyclerView recyclerView = findViewById(R.id.recycler);
        ZujiAdapter adapter = new ZujiAdapter(this, mList);
        TextView noDataView = findViewById(R.id.no_data);
        recyclerView.setAdapter(adapter);
        setRecycleView(recyclerView);
        recyclerView.setLoadMoreEnable(false);
        recyclerView.setRefreshEnable(false);
        if(mList.size() == 0){
            noDataView.setVisibility(View.VISIBLE);
            recyclerView.setVisibility(View.GONE);
        }
    }

    private void initData() {
        mList = DataSupport.where().limit(7).order("id desc").find(ZuJi.class);
//        for (ZuJi zj :mList) {
//            List<ZuJiInfo> tempList = zj.getZuJiList();
//            zj.setList(tempList);
//        }

        Iterator<ZuJi> iterator = mList.iterator();
        while (iterator.hasNext()){
            ZuJi next = iterator.next();
            List<ZuJiInfo> tempList = next.getZuJiList();
            if(tempList.size() == 0){
                iterator.remove();
            }else {
                next.setList(tempList);
            }
        }
    }
}
